﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DGSFramework;

namespace Framework
{
    public partial class AboutUs : System.Web.UI.Page
    {
        public DGSFrameworkEntities entity = new DGSFrameworkEntities();

        public List<udv_Categories> allCate = new List<udv_Categories>();
        public List<udv_Articles> allArt = new List<udv_Articles>();
        public udv_Articles articleDetails = new udv_Articles();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadCacheArticle();
                LoadArticles();
                LoadAboutUs();
                //LoadTopCommentary();
            }
        }
        public void LoadAboutUs()
        {
            try
            {
                var ab = entity.udv_Articles.Where(a => a.ArticleID == 48).ToList();
                foreach (var item in ab)
                {
                    ltrArticleContent.Text = Globals.GetLanguage(item.Body, item.Body_en, true);
                }

            }
            catch (Exception ex)
            {

                throw;
            }
        }
        public void LoadCacheArticle()
        {
            if (Cache["Article"] == null)
            {
                Cache["Article"] = allArt = entity.udv_Articles.Include("udv_Categories").ToList();
            }
            else
            {
                allArt = (List<udv_Articles>)Cache["Article"];
            }
        }
        public void LoadArticles()
        {
            try
            {
                //var lstTopArticle = allArt.OrderBy(ar => ar.DisplayOrder).ThenByDescending(ar => ar.AddedDate).Take(4).ToList();
                var lstTopArticle = (from a in entity.udv_Articles
                                     join b in entity.udv_Categories on a.udv_Categories.CateID equals b.CateID
                                     where b.IsTop == true
                                     select new
                                     {
                                         a.ArticleID,
                                         a.Title,
                                         a.Title_en,
                                         a.Abstract,
                                         a.Abstract_en,
                                         a.UrlRewrite,
                                         a.ImageUrl,
                                         a.UpdatedDate,
                                         a.AddedDate,
                                         a.DisplayOrder
                                     }).OrderBy(d => d.DisplayOrder).ThenByDescending(d => d.AddedDate).Take(5).ToList();
                rptHotNews.DataSource = lstTopArticle;
                rptHotNews.DataBind();
            }
            catch (Exception ex)
            {

                throw;
            }

        }
        //public void LoadTopCommentary()
        //{
        //    try
        //    {
        //        //var lstTopArticle = allArt.OrderBy(ar => ar.DisplayOrder).ThenByDescending(ar => ar.AddedDate).Take(4).ToList();
        //        var lstTopArticle = (from a in entity.udv_Articles
        //                             join b in entity.udv_Categories on a.udv_Categories.CateID equals b.CateID
        //                             where b.IsTop == false && a.udv_Categories.CateID == 28
        //                             select new
        //                             {
        //                                 a.ArticleID,
        //                                 a.Title,
        //                                 a.Title_en,
        //                                 a.Abstract,
        //                                 a.Abstract_en,
        //                                 a.UrlRewrite,
        //                                 a.ImageUrl,
        //                                 a.UpdatedDate,
        //                                 a.AddedDate,
        //                                 a.DisplayOrder,
        //                                 a.ImageAlt
        //                             }).OrderBy(d => d.DisplayOrder).ThenByDescending(d => d.AddedDate).Take(4).ToList();
        //        rptTopCommentary.DataSource = lstTopArticle;
        //        rptTopCommentary.DataBind();
        //    }
        //    catch (Exception ex)
        //    {

        //        throw;
        //    }
        //}

    }
}